import * as supertest from "supertest";
import { App } from "../App";
import { DriverFactory } from "@atinc/chaos/repository";
import { DBConnecter } from "@atinc/eros/database";


export class Agent {

    private static readonly _app = new App(8120);

    private static readonly _agents: Map<Symbol, supertest.SuperTest<supertest.Test>> = new Map<Symbol, supertest.SuperTest<supertest.Test>>();

    public static app(): App {
        return Agent._app;
    }

    public static initialize(): void {
        Agent._app.initialize();
    }

    public static get(): supertest.SuperTest<supertest.Test> {
        Agent.app();
        const driver =  DriverFactory.createSync("mongodb://root:123456@127.0.0.1/test");
        DBConnecter.setDriver(driver);
        Agent.initialize();
        const agent = supertest.agent(Agent._app.server.callback());
        return agent;
    }
}

export const request = Agent.get();
